package com.handinfo.game;

import java.io.DataInputStream;
import java.io.IOException;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import com.handinfo.engine.AbstractGameScreen;
import com.handinfo.engine.Actor;
import com.handinfo.engine.GameManager;
import com.handinfo.engine.resource.ObjectAdapter;
import com.handinfo.engine.resource.ResHead;
import com.handinfo.engine.resource.ResourceManager;
import com.handinfo.engine.resource.SerializeableImage;
import com.handinfo.uimenu.UIManager;
import com.handinfo.uimenu.UITools;
import com.handinfo.util.Tools;

/**
 * <pre>
 * 道具集合:道具背包，装备背包，仓库背包，宠物背包
 * 
 * <pre>
 * 道具分类：大类型，子类型
 * 
 * <pre>
 * 大类型：装备，消耗品，材料，任务，其他 子类型
 * 
 * <pre>
 * 小类型：根据具体的大类型进行细分，参看下述代码
 * 
 * <pre>
 * 个别使用频繁，具有独特属性的道具用类标示：装备类（ActorItemEquip），消耗类（ActorItemConsume ），坐骑类（ActorItemRide）
 * 
 * @author venizeng
 * 
 */
public class ActorItem {
	// zeng ：背包类型
	public static final byte TYPE_BAG_ROLE = 0;// 道具背包
	public static final byte TYPE_BAG_EQUIP = 1;// 装备背包
	public static final byte TYPE_BAG_STORAGE = 2;// 仓库背包
	public static final byte TYPE_BAG_PET = 3;// 宠物背包
	// zeng ：物品的类型
	public static final byte TYPE_GOODS_NONE = -1;// 无
	public static final byte TYPE_GOODS_ALL = 0;// 全部
	public static final byte TYPE_GOODS_EQUIPMENT = 1;// 装备
	public static final byte TYPE_GOODS_CONSUME = 2;// 消耗
	public static final byte TYPE_GOODS_MATERIAL = 3;// 材料
	public static final byte TYPE_GOODS_TASK = 4;// 任务
	public static final byte TYPE_GOODS_OTHER = 5;// 其他
	// zeng :标识装备栏道具，也可用于标识图片id
	public static final byte TYPE_EQUIPMENT_WEAPON_SIN = 1;// 武器（单手）
	public static final byte TYPE_EQUIPMENT_WEAPON_MUL = 2;// 武器（双手）
	public static final byte TYPE_EQUIPMENT_WEAPON_MAG = 3;// 武器（法系）
	public static final byte TYPE_EQUIPMENT_HEAD = 4;// 头部
	public static final byte TYPE_EQUIPMENT_CLOSE = 5;// 上装
	public static final byte TYPE_EQUIPMENT_BELT = 6;// 腰带
	public static final byte TYPE_EQUIPMENT_TROUSERS = 7;// 下装
	public static final byte TYPE_EQUIPMENT_SHOES = 8;// 鞋子
	public static final byte TYPE_EQUIPMENT_NECKLACE = 9;// 项链
	public static final byte TYPE_EQUIPMENT_RING = 10;// 戒指
	public static final byte TYPE_EQUIPMENT_BANGLE = 11;// 手镯
	public static final byte TYPE_EQUIPMENT_FABAO = 12;// 法宝
	public static final byte TYPE_EQUIPMENT_NICKNAME = 13;// 称号
	public static final byte TYPE_EQUIPMENT_DRESS = 14;// 时装
	// 装备栏索引
	public static final byte INDEX_EQUIP_WEAPON = 0;// 武器
	public static final byte INDEX_EQUIPMENT_HEAD = 1;// 头部
	public static final byte INDEX_EQUIPMENT_NICKNAME = 2;// 称号
	public static final byte INDEX_EQUIPMENT_NECKLACE = 3;// 项链
	public static final byte INDEX_EQUIPMENT_BELT = 4;// 腰带
	public static final byte INDEX_EQUIPMENT_CLOSE = 5;// 上装
	public static final byte INDEX_EQUIPMENT_BANGLE = 6;// 手镯
	public static final byte INDEX_EQUIPMENT_RING = 7;// 戒指
	public static final byte INDEX_EQUIPMENT_SHOES = 8;// 鞋子
	public static final byte INDEX_EQUIPMENT_TROUSERS = 9;// 下装
	public static final byte INDEX_EQUIPMENT_DRESS = 10;// 时装
	public static final byte INDEX_EQUIPMENT_FABAO = 11;// 法宝
	// zeng 消耗
	public static final byte TYPE_CONSUME_DRUG = 1;// 血蓝药 1
	public static final byte TYPE_CONSUME_DRUG_STATE = 2;// 状态药
	public static final byte TYPE_CONSUME_DRUG_ADD = 3;// 增强药
	public static final byte TYPE_CONSUME_TRANSLATE = 4;// 传送卷
	public static final byte TYPE_CONSUME_STRIKE = 5;// 触发任务卷
	public static final byte TYPE_CONSUME_BOX = 6;// 可开启的宝箱
	public static final byte TYPE_CONSUME_SPEAKER = 7;// 喇叭
	public static final byte TYPE_CONSUME_ADD_EXP = 11; // 加经验类道具
	public static final byte TYPE_CONSUME_ADD_SPEED_JBP = 12; // 洞府 聚宝盆加速类道具
	public static final byte TYPE_CONSUME_ADD_SPEED_BGL = 13; // 洞府 八卦炉加速类道具
	public static final byte TYPE_CONSUME_ADD_SPEED_TGF = 14; // 洞府 天工坊加速类道具
	// zeng 材料
	public static final byte TYPE_MATERIAL_NORMAL = 1;// 普通材料
	public static final byte TYPE_MATERIAL_FUNCTION = 2;// 功能材料
	public static final byte TYPE_MATERIAL_BAOSHI = 3;// 宝石
	public static final byte TYPE_MATERIAL_PAPER_BAGUALU = 4;// 八卦炉用的图纸
	public static final byte TYPE_MATERIAL_PAPER_TIANGONGFANG = 5;// 天工坊用的图纸
	// public static final byte TYPE_MATERIAL_PAPER_JUBAOPEN = 12;// 聚宝盆的种子
	// zeng 任务
	public static final byte TYPE_TASK_STRIKE = 1;// 触发任务卷
	public static final byte TYPE_TASK_MATERIAL_FUNCTION = 2;// 任务材料
	// zeng other
	public static final byte TYPE_OTHER_PROVE = 1;// 副本证明
	public static final byte TYPE_OTHER_SPECIAL = 2;// 特殊功能消耗
	public static final byte TYPE_OTHER_PET = 3;// 宠物
	public static final byte TYPE_OTHER_RIDE = 4;// 坐骑
	public static final byte TYPE_OTHER_KEY = 5;// 钥匙
	/**
	 * 操作类型,
	 */
	public static final int INDEX_TYPE_OPER_DROP = 0;// 是否可丢弃
	public static final int INDEX_TYPE_OPER_DEAL_WITH_NPC = 1;// 是否可出售
	public static final int INDEX_TYPE_OPER_DEAL_WITH_PLAYER = 2;// 是否可与玩家交易
	public static final int INDEX_TYPE_OPER_QIANGHUA = 3;// 是否可以强化
	public static final int INDEX_TYPE_OPER_RESOLVE = 4;// 是否可分解
	public static final int INDEX_TYPE_OPER_USE_AT_ANYTIME = 5;// 是否可以在任意时间使用
	public static final int INDEX_TYPE_OPER_USER_AT_FIGHT = 6;// 是否可以在战斗时间使用
	/**
	 * 绑定类型
	 */
	public static final int TYPE_BANGDING_NONE = 0;// 不绑定
	public static final int TYPE_BANGDING_EQUIP = 1;// 装备后绑定
	public static final int TYPE_BANGDING_PICK = 2;// 拾取后绑定
	public static final int TYPE_BANGDING_USE = 3;// 使用后绑定

	// 道具的标示
	public static final int ID_NONE = -1;// 道具Id
	//
	public static Image s_icon;
	//
	public byte m_layer_actorItem;// 标识哪一个背包
	public int m_index;// 在当前item列表中的顺序
	public String m_key;// 标示I
	public long m_guid = -1;// 唯一标示
	public byte m_type = ActorItem.TYPE_GOODS_NONE;
	public byte m_type_detail;// 具体类型小类型
	public int m_num;
	public String m_name = "";
	public String m_describe = "";// 描述
	public int m_iconId; // 图标id
	public int m_iconCoverId; // 图标蒙板id
	public long m_money_sail;// 出售价格
	public boolean m_isOperLocked = false;// 是否绑定
	public String m_url;// 赵铮URL
	public byte m_xiyoudu = 1;// 稀有度
	public int m_type_oper;// 操作类型

	static {
		ResHead head = new ResHead(ObjectAdapter.RESOURCE_TYPE_PNG, UIManager.RES_ACTORITEM, 1);
		s_icon = ((SerializeableImage) ResourceManager.getInstance().loadResource(GameManager.getInstance().m_resource_static, head)).m_image;
	}

	public static void initStaticResource() {
		ResHead head = new ResHead(ObjectAdapter.RESOURCE_TYPE_PNG, UIManager.RES_ACTORITEM, 1);
		s_icon = ((SerializeableImage) ResourceManager.getInstance().loadResource(GameManager.getInstance().m_resource_static, head)).m_image;
	}

	public static void disposeStaticResource() {
		if (s_icon == null) {
			return;
		}
		ResHead head = new ResHead(ObjectAdapter.RESOURCE_TYPE_PNG, UIManager.RES_ACTORITEM, 1);
		ResourceManager.getInstance().removeResource(GameManager.getInstance().m_resource_static, head);
		s_icon = null;
	}

	public static final ActorItem recvActorItemFormServer2(DataInputStream dis) throws IOException {
		byte layer = dis.readByte();
		int index = dis.readInt();
		String key = dis.readUTF();
		long guid = dis.readLong();
		byte type = dis.readByte();
		byte subType = dis.readByte();
		short num = dis.readShort();
		String name = dis.readUTF();
		String describe = dis.readUTF();
		short picId = dis.readShort();
		short coverId = dis.readShort();
		long price = dis.readLong();
		String url = dis.readUTF();// URL 赵铮
		byte xiyoudu = dis.readByte();// 稀有度
		int type_oper = dis.readInt();// 操作类型
		byte type_bangding = dis.readByte();// 绑定类型

		ActorItem item = null;
		// 创建对象
		switch (type) {
		case TYPE_GOODS_EQUIPMENT:
			item = new ActorItemEquip();
			break;
		case TYPE_GOODS_OTHER:
			switch (subType) {
			case TYPE_OTHER_RIDE:
				item = new ActorItemRide();
				break;
			default:
				item = new ActorItem();
				break;
			}
			break;
		case TYPE_GOODS_CONSUME:
			item = new ActorItemConsume();
			break;
		case TYPE_GOODS_MATERIAL:
			switch (subType) {
			case TYPE_MATERIAL_PAPER_BAGUALU:
			case TYPE_MATERIAL_PAPER_TIANGONGFANG:
				item = new ActorItemFomula();
				break;
			default:
				item = new ActorItem();
				break;
			}
			break;
		default:
			item = new ActorItem();
			break;
		}
		item.m_layer_actorItem = layer;
		item.m_index = index;
		item.m_key = key;
		item.m_guid = guid;
		item.m_type = type;
		item.m_type_detail = subType;
		item.m_num = num;
		item.m_name = name;
		item.m_describe = describe;
		item.m_iconId = picId;
		item.m_iconCoverId = coverId;
		item.m_money_sail = price;
		item.m_xiyoudu = xiyoudu;// 稀有度
		item.m_type_oper = type_oper;// 操作类型
		item.m_isOperLocked = type_bangding == 1 ? true : false;// 绑定类型
		//
		switch (type) {
		case TYPE_GOODS_EQUIPMENT: {
			ActorItemEquip equip = (ActorItemEquip) item;
			int levelNum = dis.readByte();
			switch (subType) {
			case ActorItem.TYPE_EQUIPMENT_WEAPON_MAG:
			case ActorItem.TYPE_EQUIPMENT_WEAPON_MUL:
			case ActorItem.TYPE_EQUIPMENT_WEAPON_SIN:
				if (url.length() > 1) {
					url.trim();
					item.m_url = ObjectAdapter.DIR_ANIM.concat(url).concat(ObjectAdapter.EXTENSION_ANIM);// 读取角色动画资源URL
				}
				// Tools.debugPrintln("购买武器的URL=" + item.m_url);
				break;
			case ActorItem.TYPE_EQUIPMENT_DRESS:
				if (url.length() > 1) {
					url.trim();
					item.m_url = url;
				}
				// Tools.debugPrintln("购买的URL=" + item.m_url);
				break;
			}
			for (int i = 0; i < levelNum; i++) {
				byte leveltype = dis.readByte();
				switch (leveltype) {
				case ActorItemEquip.TYPE_PHY:
					equip.m_level_phy = dis.readByte();
					break;
				case ActorItemEquip.TYPE_MAGIC:
					equip.m_level_magic = dis.readByte();
					break;
				case ActorItemEquip.TYPE_DEFENCE:
					equip.m_level_defence = dis.readByte();
					break;
				}
			}
			// 宝石
			int jewelNum = dis.readByte();
			if (jewelNum > 0) {
				equip.m_color_jewels = new byte[jewelNum];
				equip.m_isXiangqian_jewels = new boolean[jewelNum];
				for (int i = 0; i < jewelNum; i++) {
					equip.m_color_jewels[i] = dis.readByte();
					equip.m_isXiangqian_jewels[i] = dis.readBoolean();
				}
			}
			// 耐久
			equip.m_naijiu = dis.readShort();
			equip.m_maxNaijiu = dis.readShort();
		}
			break;
		case TYPE_GOODS_OTHER:
			switch (subType) {
			case TYPE_OTHER_RIDE: {
				ActorItemRide ride = (ActorItemRide) item;
				if (url.length() > 1) {
					ride.m_url = ObjectAdapter.DIR_ANIM.concat(url).concat(ObjectAdapter.EXTENSION_ANIM);// 读取角色动画资源URL;//TODO赵铮
				}
				// Tools.debugPrintln("购买坐骑的URL=" + ride.m_url);
				ride.m_speed = dis.readInt() / GameManager.FRAME_PER_SECOND << Actor.ACTOR_FRACTION_BIT;
				// Tools.debugPrintln("ride.m_speed=" + ride.m_speed);
				ride.m_rideType = dis.readByte();
				Tools.debugPrintln("item.m_rideType=" + ((ActorItemRide) item).m_rideType);
				// Tools.debugPrintln("ride.m_rideType=" + ride.m_rideType);
				break;
			}
			}
			break;
		case TYPE_GOODS_CONSUME: {
			ActorItemConsume consume = (ActorItemConsume) item;
			consume.m_cd_type = dis.readInt();
			consume.m_time_cd = dis.readLong();
		}
			break;
		case TYPE_GOODS_MATERIAL:
			switch (subType) {
			case TYPE_MATERIAL_NORMAL:
				dis.readByte();
				break;
			case TYPE_MATERIAL_PAPER_BAGUALU:
			case TYPE_MATERIAL_PAPER_TIANGONGFANG:
				ActorItemFomula material = (ActorItemFomula) item;
				material.m_grade = dis.readByte();
				break;
			}
			break;
		}
		return item;
	}

	public static final ActorItem recvActorItemFormServer(DataInputStream dis) throws IOException {
		byte layer = dis.readByte();
		int index = dis.readInt();
		String key = dis.readUTF();
		long guid = dis.readLong();
		byte type = dis.readByte();
		byte subType = dis.readByte();
		short num = dis.readShort();
		String name = dis.readUTF();
		String describe = dis.readUTF();
		short picId = dis.readShort();
		short coverId = dis.readShort();
		long price = dis.readLong();
		String url = dis.readUTF();// URL 赵铮
		byte xiyoudu = dis.readByte();// 稀有度
		int type_oper = dis.readInt();// 操作类型
		byte type_bangding = dis.readByte();// 绑定类型
		byte test = dis.readByte();
		ActorItem item = null;
		// 创建对象
		// 创建对象
		switch (type) {
		case TYPE_GOODS_EQUIPMENT:
			item = new ActorItemEquip();
			break;
		case TYPE_GOODS_OTHER:
			switch (subType) {
			case TYPE_OTHER_RIDE:
				item = new ActorItemRide();
				break;
			default:
				item = new ActorItem();
				break;
			}
			break;
		case TYPE_GOODS_CONSUME:
			item = new ActorItemConsume();
			break;
		case TYPE_GOODS_MATERIAL:
			switch (subType) {
			case TYPE_MATERIAL_PAPER_BAGUALU:
			case TYPE_MATERIAL_PAPER_TIANGONGFANG:
				item = new ActorItemFomula();
				break;
			default:
				item = new ActorItem();
				break;
			}
			break;
		default:
			item = new ActorItem();
			break;
		}

		item.m_layer_actorItem = layer;
		item.m_index = index;
		item.m_key = key;
		item.m_guid = guid;
		item.m_type = type;
		item.m_type_detail = subType;
		item.m_num = num;
		item.m_name = name;
		item.m_describe = describe;
		item.m_iconId = picId;
		item.m_iconCoverId = coverId;
		item.m_money_sail = price;
		item.m_xiyoudu = xiyoudu;// 稀有度
		item.m_type_oper = type_oper;// 操作类型
		item.m_isOperLocked = type_bangding == 1 ? true : false;// 绑定类型
		//

		switch (test) {
		case 0:// 装备,//0
		{
			ActorItemEquip equip = (ActorItemEquip) item;
			int levelNum = dis.readByte();
			switch (subType) {
			case ActorItem.TYPE_EQUIPMENT_WEAPON_MAG:
			case ActorItem.TYPE_EQUIPMENT_WEAPON_MUL:
			case ActorItem.TYPE_EQUIPMENT_WEAPON_SIN:
				if (url.length() > 1) {
					url.trim();
					item.m_url = ObjectAdapter.DIR_ANIM.concat(url).concat(ObjectAdapter.EXTENSION_ANIM);// 读取角色动画资源URL
				}
				// Tools.debugPrintln("购买武器的URL=" + item.m_url);
				break;
			case ActorItem.TYPE_EQUIPMENT_DRESS:
				if (url.length() > 1) {
					url.trim();
					item.m_url = url;
				}
				// Tools.debugPrintln("购买的URL=" + item.m_url);
				break;
			}
			for (int i = 0; i < levelNum; i++) {
				byte leveltype = dis.readByte();
				switch (leveltype) {
				case ActorItemEquip.TYPE_PHY:
					equip.m_level_phy = dis.readByte();
					break;
				case ActorItemEquip.TYPE_MAGIC:
					equip.m_level_magic = dis.readByte();
					break;
				case ActorItemEquip.TYPE_DEFENCE:
					equip.m_level_defence = dis.readByte();
					break;
				}
			}
			// 宝石
			int jewelNum = dis.readByte();
			if (jewelNum > 0) {
				equip.m_color_jewels = new byte[jewelNum];
				equip.m_isXiangqian_jewels = new boolean[jewelNum];
				for (int i = 0; i < jewelNum; i++) {
					equip.m_color_jewels[i] = dis.readByte();
					equip.m_isXiangqian_jewels[i] = dis.readBoolean();
				}
			}
			// 耐久
			equip.m_naijiu = dis.readShort();
			equip.m_maxNaijiu = dis.readShort();
		}
			break;
		case 1:// 材料,//1
			dis.readByte();
			break;
		case 2: // 消耗品,//2
		case 9:// 礼包,//9
		case 12://宝箱
		case 13://功能道具
		case 10:// 副本宝箱,//10
			ActorItemConsume consume = (ActorItemConsume) item;
			consume.m_cd_type = dis.readInt();
			consume.m_time_cd = dis.readLong();
			break;
		case 3:// 宝石,//3
			break;
		case 4: // 图纸,//4
			ActorItemFomula material = (ActorItemFomula) item;
			material.m_grade = dis.readByte();
			break;
		case 5:// 坐骑,//5
			ActorItemRide ride = (ActorItemRide) item;
			if (url.length() > 1) {
				ride.m_url = ObjectAdapter.DIR_ANIM.concat(url).concat(ObjectAdapter.EXTENSION_ANIM);// 读取角色动画资源URL;//TODO赵铮
			}
			// Tools.debugPrintln("购买坐骑的URL=" + ride.m_url);
			ride.m_speed = dis.readInt() / GameManager.FRAME_PER_SECOND << Actor.ACTOR_FRACTION_BIT;
			// Tools.debugPrintln("ride.m_speed=" + ride.m_speed);
			ride.m_rideType = dis.readByte();
			Tools.debugPrintln("item.m_rideType=" + ((ActorItemRide) item).m_rideType);
			break;
		case 6:// 任务道具,//6
			break;
		case 7:// 其他,//7
			break;
		case 8:// 副本证明,//8
			break;
		case 11:// 宠物,//11
			break;
		default:
			break;
		}
		return item;
	}

	public static final ActorItem clone(ActorItem item) {
		byte layer = item.m_layer_actorItem;
		int index = item.m_index;
		String key = item.m_key;
		long guid = item.m_guid;
		byte type = item.m_type;
		byte subType = item.m_type_detail;
		int num = item.m_num;
		String name = item.m_name;
		String describe = item.m_describe;
		int iconId = item.m_iconId;
		int coverId = item.m_iconCoverId;
		long moneySail = item.m_money_sail;
		boolean isOperLocked = item.m_isOperLocked;
		ActorItem tempItem = null;
		switch (type) {
		case TYPE_GOODS_EQUIPMENT:
			tempItem = new ActorItemEquip();
			break;
		case TYPE_GOODS_OTHER:
			switch (subType) {
			case TYPE_OTHER_RIDE:
				tempItem = new ActorItemRide();
				break;
			}
			break;
		case TYPE_GOODS_CONSUME:
			tempItem = new ActorItemConsume();
			break;
		case TYPE_GOODS_MATERIAL:
			tempItem = new ActorItemFomula();
			break;
		}
		if (tempItem == null) {
			tempItem = new ActorItem();
		}
		tempItem.m_layer_actorItem = layer;
		tempItem.m_index = index;
		tempItem.m_key = key;
		tempItem.m_guid = guid;
		tempItem.m_type = type;
		tempItem.m_type_detail = subType;
		tempItem.m_num = num;
		tempItem.m_name = name;
		tempItem.m_describe = describe;
		tempItem.m_iconId = iconId;
		tempItem.m_iconCoverId = coverId;
		tempItem.m_money_sail = moneySail;
		tempItem.m_isOperLocked = isOperLocked;
		switch (type) {
		case TYPE_GOODS_EQUIPMENT: {
			ActorItemEquip equip = (ActorItemEquip) tempItem;
			ActorItemEquip temp = (ActorItemEquip) item;
			equip.m_level_magic = temp.m_level_magic;
			equip.m_level_phy = temp.m_level_phy;
			equip.m_level_defence = temp.m_level_defence;
			equip.m_color_jewels = temp.m_color_jewels;
			equip.m_isXiangqian_jewels = temp.m_isXiangqian_jewels;
		}
			break;
		case TYPE_GOODS_OTHER:
			switch (subType) {
			case TYPE_OTHER_RIDE: {
				ActorItemRide ride = (ActorItemRide) tempItem;
				ActorItemRide temp = (ActorItemRide) item;
				ride.m_url = temp.m_url;
				ride.m_speed = temp.m_speed;
				ride.m_rideType = temp.m_rideType;
				break;
			}
			}
			break;
		case TYPE_GOODS_CONSUME: {
			ActorItemConsume consume = (ActorItemConsume) tempItem;
			ActorItemConsume temp = (ActorItemConsume) item;
			consume.m_type = temp.m_type;
			consume.m_time_cd = temp.m_time_cd;
		}
			break;
		case TYPE_GOODS_MATERIAL:
			switch (subType) {
			case TYPE_MATERIAL_PAPER_BAGUALU:
			case TYPE_MATERIAL_PAPER_TIANGONGFANG:
				ActorItemFomula material = (ActorItemFomula) tempItem;
				ActorItemFomula temp = (ActorItemFomula) tempItem;
				material.m_grade = temp.m_grade;
				break;
			}
		}
		return tempItem;
	}

	/**
	 * 是否可以丢弃 2012-4-16 下午02:47:51 venizeng
	 * 
	 * @return
	 */
	public boolean isCanDrop() {
		return Tools.getBitNum(m_type_oper, INDEX_TYPE_OPER_DROP);// 可丢弃;
	}

	/**
	 * 是否可以和Npc交互 2012-4-16 下午02:48:13 venizeng
	 * 
	 * @return
	 */
	public boolean isCanDealWithNpc() {
		return Tools.getBitNum(m_type_oper, INDEX_TYPE_OPER_DEAL_WITH_NPC);// ;
	}

	/**
	 * 是否可以玩家交易 2012-4-16 下午02:55:51 venizeng
	 * 
	 * @return
	 */
	public boolean isCanDealWithPlayer() {
		return Tools.getBitNum(m_type_oper, INDEX_TYPE_OPER_DEAL_WITH_PLAYER);// ;
	}

	/**
	 * 是否可强化 2012-4-16 下午02:57:43 venizeng
	 * 
	 * @return
	 */
	public boolean isCanQianghua() {
		return Tools.getBitNum(m_type_oper, INDEX_TYPE_OPER_QIANGHUA);// ;
	}

	/**
	 * 是否可以在任意时候使用 2012-4-16 下午03:07:46 venizeng
	 * 
	 * @return
	 */
	public boolean isCanUseAtAnyTime() {
		return Tools.getBitNum(m_type_oper, INDEX_TYPE_OPER_USE_AT_ANYTIME);// ;
	}

	/**
	 * 是否可以在战斗过程中使用 2012-4-16 下午03:07:59 venizeng
	 * 
	 * @return
	 */
	public boolean isCanUseAtFight() {
		return Tools.getBitNum(m_type_oper, INDEX_TYPE_OPER_USER_AT_FIGHT);//
	}

	/**
	 * 获得相应操作无法实现所对应的提示文字 2012-4-16 下午02:25:28 venizeng
	 * 
	 * @return
	 */
	public static String getOperTypeErrStr(int index) {
		switch (index) {
		case INDEX_TYPE_OPER_DEAL_WITH_NPC:
			return "此道具不能出售";
		case INDEX_TYPE_OPER_DEAL_WITH_PLAYER:
			return "此道具不能交易";
		case INDEX_TYPE_OPER_DROP:
			return "此道具不能销毁";
		case INDEX_TYPE_OPER_QIANGHUA:
			return "此道具不能强化";
		case INDEX_TYPE_OPER_RESOLVE:
			return "此道具不能分解";
		case INDEX_TYPE_OPER_USE_AT_ANYTIME:
			return "此道具不能使用";
		case INDEX_TYPE_OPER_USER_AT_FIGHT:
			return "此道具不能在战斗中使用";
		default:
			break;
		}
		return "";
	}

	public boolean isFitforShortcut() {
		if (m_type == ActorItem.TYPE_GOODS_CONSUME && m_type_detail == ActorItem.TYPE_CONSUME_DRUG) {
			return true;
		} else if (m_type == ActorItem.TYPE_GOODS_OTHER && m_type_detail == ActorItem.TYPE_OTHER_RIDE) {
			return true;
		}
		return false;
	}

	public static String getActorItemTypeName(byte type, byte subType) {
		switch (type) {
		case TYPE_GOODS_EQUIPMENT:
			switch (subType) {
			case TYPE_EQUIPMENT_WEAPON_SIN:
				return "单手轻武器";
			case TYPE_EQUIPMENT_WEAPON_MUL:
				return "双手重武器";
			case TYPE_EQUIPMENT_WEAPON_MAG:
				return "法系武器";
			case TYPE_EQUIPMENT_HEAD:
				return "头部";
			case TYPE_EQUIPMENT_CLOSE:
				return "上装";
			case TYPE_EQUIPMENT_BELT:
				return "腰带";
			case TYPE_EQUIPMENT_TROUSERS:
				return "下装";
			case TYPE_EQUIPMENT_SHOES:
				return "鞋子";
			case TYPE_EQUIPMENT_NECKLACE:
				return "项链";
			case TYPE_EQUIPMENT_RING:
				return "戒指";
			case TYPE_EQUIPMENT_BANGLE:
				return "手镯";
			case TYPE_EQUIPMENT_FABAO:
				return "法宝";
			case TYPE_EQUIPMENT_NICKNAME:
				return "称号";
			case TYPE_EQUIPMENT_DRESS:
				return "时装";
			default:
				// throw new IllegalArgumentException("无此类型 Type = " + type
				// + " SubType = " + subType);
				return "";
			}
		case TYPE_GOODS_CONSUME:
			switch (subType) {
			case TYPE_CONSUME_DRUG:
				return "血蓝药 ";
			case TYPE_CONSUME_DRUG_STATE:
				return "解状态药";
			case TYPE_CONSUME_DRUG_ADD:
				return "增强药";
			case TYPE_CONSUME_TRANSLATE:
				return "传送卷";
			case TYPE_CONSUME_STRIKE:
				return "加速类道具";
			case TYPE_CONSUME_ADD_EXP:
				return "加经验类道具";
			case TYPE_CONSUME_ADD_SPEED_JBP:
				return "聚宝盆加速道具";
			case TYPE_CONSUME_ADD_SPEED_BGL:
				return "八卦炉加速道具";
			case TYPE_CONSUME_ADD_SPEED_TGF:
				return "天工坊加速道具";
			default:
				// throw new IllegalArgumentException("无此类型 Type = " + type
				// + " SubType = " + subType);
				return "";
			}
		case TYPE_GOODS_MATERIAL:
			switch (subType) {
			case TYPE_MATERIAL_NORMAL:
				return "普通材料 ";
			case TYPE_MATERIAL_FUNCTION:
				return "功能材料";
			case TYPE_MATERIAL_BAOSHI:
				return "宝石";
			case TYPE_MATERIAL_PAPER_BAGUALU:
				return "八卦炉用的图纸";
			case TYPE_MATERIAL_PAPER_TIANGONGFANG:
				return "天工坊用的图纸";
				// case TYPE_MATERIAL_PAPER_JUBAOPEN:
				// return "聚宝盆的种子";
			default:
				// throw new IllegalArgumentException("无此类型 Type = " + type
				// + " SubType = " + subType);
				return "";
			}
		case TYPE_GOODS_TASK:
			switch (subType) {
			case TYPE_TASK_STRIKE:
				return "触发任务卷 ";
			case TYPE_TASK_MATERIAL_FUNCTION:
				return "任务材料";
			default:
				// throw new IllegalArgumentException("无此类型 Type = " + type
				// + " SubType = " + subType);
				return "";
			}
		case TYPE_GOODS_OTHER:
			switch (subType) {
			case TYPE_OTHER_PROVE:
				return "副本证明 ";
			case TYPE_OTHER_SPECIAL:
				return "特殊功能消耗";
			case TYPE_OTHER_PET:
				return "宠物 ";
			case TYPE_OTHER_RIDE:
				return "坐骑";
			default:
				// throw new IllegalArgumentException("无此子类型 Type = " + type
				// + " SubType = " + subType);
				return "";
			}
		default:
			// throw new IllegalArgumentException("无此类型" + type)
			return "";
		}
	}

	public void drawIcon(Graphics g, int x, int y, int anchor) {
		drawIcon(g, x, y, anchor, anchor, m_iconId, m_iconCoverId, m_num, m_isOperLocked);
	}

	public static final void drawIcon(Graphics g, int x, int y, int anchor, long m_guid, int m_iconId, int m_iconCoverId, int m_num, boolean isOperLocked) {
		if (s_icon == null) {
			return;
		}
		if (m_guid == ID_NONE) {
			return;
		}
		// ///游戏场景中用到的各图标均使用GameScene中的s_img_icon
		if (m_iconId > 0) {
			short id = (short) (m_iconId - 1);
			AbstractGameScreen.drawRegion(g, GameScene.s_img_icon, (id % GameScene.SIZE_IMG_ICON[2]) * GameScene.SIZE_IMG_ICON[0], (id / GameScene.SIZE_IMG_ICON[2])
					* GameScene.SIZE_IMG_ICON[1], GameScene.SIZE_IMG_ICON[0], GameScene.SIZE_IMG_ICON[1], 0, x, y, anchor);
		}
		if (m_iconCoverId > 0) {
			short id = (short) (m_iconCoverId - 1);
			AbstractGameScreen.drawRegion(g, GameScene.s_img_icon_cover, (id % GameScene.SIZE_IMG_ICON[2]) * GameScene.SIZE_IMG_ICON[0], (id / GameScene.SIZE_IMG_ICON[2])
					* GameScene.SIZE_IMG_ICON[1], GameScene.SIZE_IMG_ICON[0], GameScene.SIZE_IMG_ICON[1], 0, x, y, anchor);
		}
		if (m_num > 1) {
			Tools.drawNumber(g, GameScene.s_img_num, x, y, UITools.W_NUM, UITools.H_NUM, m_num, 0, Tools.LEFT_TOP, false);
		}

		if (isOperLocked) {
			g.drawImage(UIManager.IMAGE_ACTORITEM_LOCK, x, y + GameScene.SIZE_IMG_ICON[1], Graphics.LEFT | Graphics.BOTTOM);
		}
	}

	public final void drawIconOnShortcut(Graphics g, int x, int y) {
		if (s_icon == null) {
			return;
		}
		if (m_guid == ID_NONE) {
			return;
		}
		// ///游戏场景中用到的各图标均使用GameScene中的s_img_icon
		if (m_iconId > 0) {
			short id = (short) (m_iconId - 1);
			AbstractGameScreen.drawRegion(g, GameScene.s_img_icon, (id % GameScene.SIZE_IMG_ICON[2]) * GameScene.SIZE_IMG_ICON[0], (id / GameScene.SIZE_IMG_ICON[2])
					* GameScene.SIZE_IMG_ICON[1], GameScene.SIZE_IMG_ICON[0], GameScene.SIZE_IMG_ICON[1], 0, x, y, 0);
		}
		if (m_iconCoverId > 0) {
			short id = (short) (m_iconCoverId - 1);
			AbstractGameScreen.drawRegion(g, GameScene.s_img_icon_cover, (id % GameScene.SIZE_IMG_ICON[2]) * GameScene.SIZE_IMG_ICON[0], (id / GameScene.SIZE_IMG_ICON[2])
					* GameScene.SIZE_IMG_ICON[1], GameScene.SIZE_IMG_ICON[0], GameScene.SIZE_IMG_ICON[1], 0, x, y, 0);
		}
		if (m_num > 1) {
			Tools.drawNumber(g, GameScene.s_img_num, x, y, UITools.W_NUM, UITools.H_NUM, m_num, 0, Tools.LEFT_TOP, false);
		}
		if (m_isOperLocked) {
			g.drawImage(UIManager.IMAGE_ACTORITEM_LOCK, x, y + GameScene.SIZE_IMG_ICON[1], Graphics.LEFT | Graphics.BOTTOM);
		}
	}

	/**
	 * 计算绘制描述区域
	 * 
	 * @param g
	 * @param actorItemX
	 * @param actorItemY
	 * @param sw
	 * @param sh
	 * @return
	 */
	public static int countDescribeX(Graphics g, int actorItemX, int actorItemY, int sw, int sh) {
		int x = actorItemX;
		while (x + W_DESCRIBE > sw) {
			x -= W_ICON;
		}
		return x;
	}

	public static final int W_DESCRIBE = 120;// 描述的宽度
	public static final int W_ICON = 20;
	public static final int H_ICON = 20;

	/**
	 * 获得测试用ActorItem数据
	 * 
	 * @param num
	 * @return
	 */
	public static ActorItem[] getTestItems(int num) {
		return getTestItems(ActorItem.TYPE_BAG_ROLE, num);
	}

	/**
	 * 获得测试用ActorItem数据
	 * 
	 * @param num
	 * @return
	 */
	public static ActorItem[] getTestItems(byte layer, int num) {
		ActorItem[] items = new ActorItem[num];
		for (int i = 0; i < items.length; i++) {
			items[i] = getTestItem(layer, i);
		}
		return items;
	}

	/**
	 * 获得测试用ActorItem数据
	 * 
	 * @param num
	 * @return
	 */
	public static ActorItem getTestItem(byte layer, int i) {
		ActorItem temp = new ActorItem();
		temp.m_layer_actorItem = layer;
		temp.m_index = i;
		temp.m_num = (short) (i % 20);
		temp.m_guid = i * 100 + i;
		temp.m_type = (byte) (i % 5 + 1);
		temp.m_key = "KEY" + i;
		temp.m_name = "ActorItem" + i;
		temp.m_describe = "describe" + i;
		switch (temp.m_type) {
		case ActorItem.TYPE_GOODS_EQUIPMENT:
			temp.m_type_detail = (byte) (i % 14 + 1);
			break;
		case ActorItem.TYPE_GOODS_CONSUME:
			// temp.m_type_detail = (byte) (i % 5 + 1);
			temp.m_type_detail = TYPE_CONSUME_DRUG;
			break;
		case ActorItem.TYPE_GOODS_MATERIAL:
			temp.m_type_detail = (byte) (i % 3 + 1);
			break;
		case ActorItem.TYPE_GOODS_TASK:
			temp.m_type_detail = (byte) (i % 2 + 1);
			break;
		case ActorItem.TYPE_GOODS_OTHER:
			temp.m_type_detail = (byte) (i % 4 + 1);
			break;
		}
		temp.m_iconId = i % 80;
		temp.m_iconCoverId = i % 80;
		temp.m_money_sail = i * 100 + 30;
		return temp;
	}

	public int drawName(Graphics g, int tempX, int tempY) {
		String temp = null;
		if (this.m_num <= 1) {
			temp = this.m_name;
		} else {
			temp = this.m_name + " X" + this.m_num;
		}
		drawName(g, temp, tempX, tempY, m_xiyoudu);
		
		return tempX + AbstractGameScreen.s_font.stringWidth(temp);
	}

	// private String[] NAME_EQUIP = new String[] { "武", "头", "腰", "胸", "足",
	// "腿", "称", "饰", "宝", "饰", "装", "饰", };
	//
	public static final String getPos(int index) {
		switch (index) {
		case 0:
			return "武";
		case 1:
			return "头";
		case 2:
			return "腰";
		case 3:
			return "胸";
		case 4:
			return "足";
		case 5:
			return "腿";
		case 6:
			return "称";
		case 7:
			return "饰";
		case 8:
			return "宝";
		case 9:
			return "饰";
		case 10:
			return "装";
		default:
			return "饰";
		}
	}

	public static void drawName(Graphics g, String name, int x, int y, byte type) {
		if (name == null) {
			return;
		}
		switch (type) {
		case 0:// 灰
			g.setColor(0xc3c2c2);
			break;
		case 1:// 白
			g.setColor(0xffffff);
			break;
		case 2:// 蓝
			g.setColor(0x5c8ff6);
			break;
		case 3:// 绿
			g.setColor(0x6cff73);
			break;
		case 4:// 金
			g.setColor(0xffdf0b);
			break;
		case 5:// 紫
			g.setColor(0xc358fb);
			break;
		case 6:// 橙
			g.setColor(0xff8a00);
			break;
		case 7:// 红
			g.setColor(0xff0000);
			break;
		default:
			g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
			break;
		}
		g.drawString(name, x, y, 0);
	}
}
